package com.gwd.task.model;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gwd.task.entity.EventsProcessEntity;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @author zhiyongming
 * @date 2020/11/26 11:22
 */
@Data
public class EventsProcessDTO {
    private Long epId;
    private Long eventId;
    @NotNull(message = "状态不能为空")
    private Integer eventState;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String operationTime;
    private String operationUserName;
    private Long operationUser;
    private String describe;

    public EventsProcessDTO() {}
    public EventsProcessDTO(EventsProcessEntity entity) {
        BeanUtil.copyProperties(entity, this);
    }
    public static EventsProcessDTO CREATE(Long userId, Long eventId) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(0);
        dto.setDescribe("生产记录");
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public static EventsProcessDTO START(Long userId, Long eventId) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(1);
        dto.setDescribe("分配确认");
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public static EventsProcessDTO RESTART(Long userId, Long eventId) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(1);
        dto.setDescribe("重启任务");
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public static EventsProcessDTO SUBMIT(Long userId, Long eventId) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(2);
        dto.setDescribe("代码提交");
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public static EventsProcessDTO TEST(Long userId, Long eventId) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(3);
        dto.setDescribe("开始测试");
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public static EventsProcessDTO FINISH(Long userId, Long eventId) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(4);
        dto.setDescribe("任务完成");
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public static EventsProcessDTO CLOSE(Long userId, Long eventId) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(4);
        dto.setDescribe("关闭");
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public static EventsProcessDTO BLOCK(Long userId, Long eventId, String describe) {
        EventsProcessDTO dto = new EventsProcessDTO();
        dto.setEventState(3);
        dto.setDescribe("被堵塞 " + describe);
        dto.setOperationUser(userId);
        dto.setEventId(eventId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }
}
